﻿Chenxin.UI.PgPersonalAchievementRank = Chenxin.extend(Chenxin.UI.PageCommon, {
    actionUrl: "/service/logic/PersonalAchievementRank.ashx",
    createSearch: function() {
        return new Chenxin.UI.SrhPersonalAchievementRank({
            scope: this
        });
    },
    createGrid: function() {
        _this = this;
        return new Chenxin.UI.ReportGrid({
            createTitleTool: function() {
                return [{
                    text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
                    scope: this,
                    title: '导出全部数据',
                    handler: function(el) {
                        _this.exportAll();
                    }
                }];
            },
            actionUrl: this.actionUrl + '?op=search',
            pageSize: 100,
            hasTotal: false,
            hasPage:true,
            cellBorder: true,
            height: 400,
            renderTo: 'divShowContractList',
            hasCheckBox: false,
            scope: this,
            autoLoad: false,
            modelId: 'EmployeeId',
            id: 'ContractList',
            title: '排行榜列表',
            scope: this,
            columns: {
                RANK_PURE: {
                    width: 40,
                    head: "名次",
					inTotal: false,
                    sortField: "SUM(Purecommision)",
                    renderer: function(val, field, row) {
                        return '<a href="javascript:void(0)" name="aDetail" value="' + row.EmployeeId + '">' + val + '</a>';
                    }
                },
                UserCode: {
                    width: 110,
                    head: "员工工号",
					inTotal: false,
					captionCol:true 
                },
                Employee: {
                    width: 100,
                    head: "员工姓名",
					inTotal: false
                },
                AreaName: {
                    width: 122,
                    head: "商圈",
					inTotal: false
                },
                Depart: {
                    width: 180,
                    head: "部门",
					inTotal: false
                },
                AllCommision: {
                    width: 80,
                    head: "应收佣收"
                },
                PureCommision: {
                    width: 80,
                    head: "业绩"
                },
                Point: {
                    width: 80,
                    head: "点数"
                },
                WorkAgeBegin: {
                    width: 100,
                    head: "年资",
					inTotal: false
                },
                Position: {
                    width: 120,
                    head: "职称",
					inTotal: false
                }
            }
        });
    },
    exportAll: function() {
        paramStr = this.search.getParamJson();
        paramStr.op = 'exportAll';
        Chenxin.Msg.Waiting.show();
        Chenxin.ajax({
            type: "get",
            dataType: "json",
            url: this.actionUrl,
            data: paramStr,
            onSuccess: function(data) {
                Chenxin.Msg.Waiting.hide();
                Chenxin.Fn.exportToExcel(data, '导出文件');
            },
            onError: function(data) {
                Chenxin.Msg.Waiting.hide();
                alert(data.msg);
            }
        });
    },
    initEvent: function() {
        var objPg = this;
        /***********事件：详情链接**********/
        $("A[name='aDetail']").live("click", function() {

            if (objPg.DetailFrm == undefined) {
                objPg.DetailFrm = new Chenxin.UI.PersonalAchievementDetailFrm({
                    scope: objPg
                });
            }
            objPg.DetailFrm.show($(this).attr("value"));
        });
    }
});

/*
* 查询面板
*/
Chenxin.UI.SrhPersonalAchievementRank = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: "divCondition",
    actionUrl: "/service/logic/PersonalAchievementRank.ashx",
    createComboList: function() {
        //在职情况
        var cmbStatus = new Chenxin.UI.Combo({
            containerId: '#Status',
            addPleaseSelected:false,
            tbxWidth: 45,
            items: comboCommon.UserStatusType
        });

        //业绩类型
        var cmbBusinessType = new Chenxin.UI.Combo({
            containerId: '#BusinessType',
            tbxWidth: 45,
            items: comboCommon.BusinessKind
        });
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        structs.push(cmbStatus);
        structs.push(cmbBusinessType);
        return structs;
    },
    initEvent: function() {
        var objSrh = this;
        /*******事件：查询按钮*******/
        $("#btSearch").click(function() {
            objSrh.scope.reloadGrid();
        });

        /********事件：开始时间******/
        $("#txtStartTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });

        /********事件：结束时间******/
        $("#txtEndTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });

        var curdate = new Date();
        $('#txtStartTime').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1) + '-1');
        if (curdate.getMonth() + 1 == 12)
            $('#txtEndTime').val(curdate.getFullYear() + 1 + '-1-1');
        else
            $('#txtEndTime').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 2) + '-1');
    }
});

/*
* 详情面板
*/
Chenxin.UI.PersonalAchievementDetailFrm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: "/service/logic/PersonalAchievementRank.ashx",
    id: "jqmDetail",
    renderTo: "jqmDetail",
    title: "业绩明细",
    jqmHasFoot:false,
    createForm: function() {
        var strRet = "";
        strRet = strRet + '<div style="margin:10px 10px 10px 10px;"><div id="divItems" ></div></div>';
        return strRet;
    },
    createGrid: function() {
        this.grid = new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=getdetail',
            pageSize: 10,
            renderTo: 'divItems',
            hasCheckBox: false,
            autoLoad: false,
            scope: this,
            id: 'DetailItems',
            title: '个人业绩明细',
            scope: this,
            columns: {
                ContractCode: {
                    width: 120,
                    head: "成交编号",
                    sortable: true
                },
                ContractDate: {
                    width: 80,
                    head: "成交日期",
                    sortable: true
                },
                HouseAddress: {
                    width: 345,
                    head: "房屋地址",
                    sortable: true
                },
                Area: {
                    width: 100,
                    head: "面积",
                    sortable: true
                },
                BargainPrice: {
                    width: 100,
                    head: "合同标的",
                    sortable: true
                },
                AllCommision: {
                    width: 100,
                    head: "应收",
                    sortable: true
                },
                AllConsulting: {
                    width: 100,
                    head: "咨询费",
                    sortable: true
                },
                PureCommision: {
                    width: 100,
                    head: "业绩",
                    sortable: true
                },
                ApportionAR: {
                    width: 100,
                    head: "分摊应收",
                    sortable: true
                },
                ApportionConsulting: {
                    width: 100,
                    head: "分摊咨询费",
                    sortable: true
                },
                ApportionCommision: {
                    width: 100,
                    head: "分摊业绩",
                    sortable: true
                },
                ArchivementDate: {
                    width: 100,
                    head: "业绩归属日期",
                    sortable: true
                },
                ContractCompanyName: {
                    width: 100,
                    head: "合同归属公司",
                    sortable: true
                }
            }
        });
    },
    show: function(UserId, permitCode, permitParam) {
        if (Chenxin.UI.PersonalAchievementDetailFrm.superclass.show.call(this, permitCode, permitParam)) {
            var dataCon = this.scope.search.getParamJson();
            dataCon.EmployeeId = UserId;
            this.grid.reload(dataCon);
            return true;
        } else {
            return false;
        }
    },
    initComponent: function() {
        Chenxin.UI.PersonalAchievementDetailFrm.superclass.initComponent.call(this);
        this.createGrid();
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.PgPersonalAchievementRank();
});